import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { defHttp } from '/@/utils/http/axios';

export const columns : BasicColumn[] = [
  {
    title: '告警名称',
    dataIndex: 'alarmName'
  },
  {
    title: '告警级别',
    dataIndex: 'alarmLevel_dictText'
  },
  {
    title: '告警状态',//0启用，1禁用
    dataIndex: 'alarmStatus',
    customRender: ({ text, record }) => {
      if (record.alarmStatus === 1) {
        return '禁用'
      }
      return '正常'
    },
  },
  {
    title: '告警描述',
    dataIndex: 'alarmRemark'
  }
];

export const searchFormSchema : FormSchema[] = [
  {
    label: '告警名称',
    field: 'alarmName',
    component: 'Input'
  },
];

export const formSchema : FormSchema[] = [
  // TODO 主键隐藏字段，目前写死为ID
  { label: '', field: 'alarmId', component: 'InputNumber', show: false },
  { label: '', field: 'isEdit', component: 'InputNumber', show: false },
  {
    label: '告警名称',
    field: 'alarmName',
    component: 'Input',
    colProps: { span: 22 },
    rules: [{ required: true, message: "请输入告警名称" }],
    dynamicDisabled: ({ values }) => {
      if (values.isEdit != undefined && values.isEdit == true) {
        return true
      } else {
        return false
      }
    },
  },
  {
    label: '告警级别', //alarm_level
    field: 'alarmLevel',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "alarm_level",
    },
    colProps: { span: 22 },
    rules: [{ required: true, message: "请选择告警级别" }],
    dynamicDisabled: ({ values }) => {
      if (values.isEdit != undefined && values.isEdit == true) {
        return true
      } else {
        return false
      }
    },
  },
  {
    label: '通知模板', //alarm_level
    field: 'noticeTemplateId',
    component: 'ApiSelect',
    colProps: { span: 22 },
    componentProps: {
      api: () => defHttp.get({ url: '/notice/noticeTemplate/list' }),
      //数值转成String
      numberToString: false,
      //标题字段
      labelField: 'templateName',
      //值字段
      valueField: 'templateId',
      //请求参数
      params: {},
      //返回结果字段
      resultField: 'records',
    },
    rules: [{ required: true, message: "请选择通知模板" }],
    dynamicDisabled: ({ values }) => {
      if (values.isEdit != undefined && values.isEdit == true) {
        return true
      } else {
        return false
      }
    },
  },
  {
    label: '触发次数',
    field: 'triggerCount',
    component: 'InputNumber',
    colProps: { span: 22 },
    rules: [{ required: true, message: "请输入触发次数" }],
    dynamicDisabled: ({ values }) => {
      if (values.isEdit != undefined && values.isEdit == true) {
        return true
      } else {
        return false
      }
    },
  },
  {
    label: '间隔时间',
    field: 'intervalTime',
    component: 'InputNumber',
    colProps: { span: 22 },
    rules: [{ required: true, message: "请输入间隔时间" }],
    dynamicDisabled: ({ values }) => {
      if (values.isEdit != undefined && values.isEdit == true) {
        return true
      } else {
        return false
      }
    },
  },
  {
    label: '告警描述',
    field: 'alarmRemark',
    component: 'Input',
    colProps: { span: 22 },
    dynamicDisabled: ({ values }) => {
      if (values.isEdit != undefined && values.isEdit == true) {
        return true
      } else {
        return false
      }
    },
  }
];
